package it.handler;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import it.protoc.ChatMessageProtos;

public class ProtoBufClientHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        System.out.println("=======================================");
        ChatMessageProtos.ChatMessage.Builder builder = ChatMessageProtos.ChatMessage.newBuilder();
        Channel channel = ctx.channel();
        builder.setName(channel.remoteAddress().toString());
        builder.setId(1);
        builder.setContent("hello!");
        ctx.writeAndFlush(builder.build());
    }


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }
}
